package com.lsh.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author ：LiuShihao
 * @date ：Created in 2020/12/16 10:17 下午
 * @desc ：创建一个定长线程池，可控制线程最大并发数，超出的线程会在队列中等待。
 */

public class NewCachedThreadPool {
    public static void main(String[] args) {
        //1.创建可固定长度的线程池
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 20; i++) {
            int finalTemp = i;
            executorService.execute(() ->{
                System.out.println(Thread.currentThread().getName()+": 第"+ finalTemp +"个线程");
            });

        }
    }

}
